package com.sasu.university_data.config;


import com.sasu.university_data.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

/**
 * 拦截器白名单配置
 * Configuration注解：被标注的类会被扫描为系统配置类
 *
 * @author qionglan
 * @version 1.0.0
 * @date 2024/06/13 15:47:13
 * @since 1.0.0
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors( InterceptorRegistry registry) {
        //配置白名单列表
        List<String> list=new ArrayList<>();
        list.add("/html/login.html");
        //list.add("/store/web/register.html");
        //list.add("/html/index.html");
        list.add("/user/login");
        list.add("/user/register");
        list.add("/html/backend/js/**");
        list.add("/html/backend/css/**");
        list.add("/html/backend/plugins/**");
        list.add("/html/backend/images/**");
        list.add("/html/backend/api/**");
        list.add("/html/backend/style/**");

        LoginInterceptor loginInterceptor = new LoginInterceptor();
        //配置拦截器规则
        registry.addInterceptor(loginInterceptor)
                //添加拦截的内容
                .addPathPatterns("/**")
                //添加不拦截的内容
                .excludePathPatterns(list);

    }
}
